﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Linq.Expressions;
using System.IO;

namespace RAMED
{
    public partial class RechercheDossierFormcs : Form
    {

        

        private List<Dossier_incomplet> DossierRecherches = new List<Dossier_incomplet>();
        public RechercheDossierFormcs()
        {
            InitializeComponent();
            RAMEDEntities1 context = SingletonContext.GetContext();
            comboBoxannexe.DataSource = context.Annexe_administratif;
            comboBoxannexe.DisplayMember = "nom_annexe_administratif";
            comboBoxannexe.SelectedItem = null;

      
        }

        private void btnrech_Click(object sender, EventArgs e)
        {
            RAMEDEntities1 CONTEXT = SingletonContext.GetContext();
            List<Dossier_incomplet> lesDossiers = new List<Dossier_incomplet>();
            lesDossiers = CONTEXT.Dossier_incomplet.ToList<Dossier_incomplet>();

            if (comboBoxannexe.SelectedItem != null)
            {
                Annexe_administratif annexeadministrative = new Annexe_administratif();
                annexeadministrative = (Annexe_administratif)comboBoxannexe.SelectedValue;
                lesDossiers = lesDossiers.Where(p => p.id_annexe_administratif == annexeadministrative.id_annexe_administratif).ToList<Dossier_incomplet>();
            }

            if (!txtCIN.Text.Trim().Equals(""))
            {

                Dossier_incomplet dossier = new Dossier_incomplet();
                lesDossiers = lesDossiers.Where(p => p.CIN.Equals(txtCIN.Text)).ToList<Dossier_incomplet>();

            }
            if (!txtnom.Text.Trim().Equals(""))
            {

                Dossier_incomplet dossier = new Dossier_incomplet();
                lesDossiers = lesDossiers.Where(p => p.Nom.ToUpper().Equals(txtnom.Text.ToUpper())).ToList<Dossier_incomplet>();

            }
            if (!txtnum.Text.Trim().Equals(""))
            {

                Dossier_incomplet dossier = new Dossier_incomplet();
                int numeroDossierSaisi = utitlitaire.CasterString(txtnum.Text);
                lesDossiers = lesDossiers.Where(p => p.num_dossier == numeroDossierSaisi).ToList<Dossier_incomplet>();

            }
            if (radiooui.Checked)
            {

                Dossier_incomplet dossier = new Dossier_incomplet();
                lesDossiers = lesDossiers.Where(p => p.complet.Equals(true)).ToList<Dossier_incomplet>();

            }
            if (radionon.Checked)
            {

                Dossier_incomplet dossier = new Dossier_incomplet();
                lesDossiers = lesDossiers.Where(p => p.complet.Equals(false)).ToList<Dossier_incomplet>();

            }
            DossierRecherches = lesDossiers;

           


            mettreAjourFormGridView();


        }

        private void RechercheDossierFormcs_Load(object sender, EventArgs e)
        {

        }
        public void mettreAjourFormGridView()
        {
            dataGridView.DataSource = null;
            remplirDataGridView();
            dataGridView.Update();
            dataGridView.Refresh();
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void txtnum_TextChanged(object sender, EventArgs e)
        {

        }

        

        private void s_Click(object sender, EventArgs e)
        {

        }

        private void btnmodifierdossier_Click(object sender, EventArgs e)
        {
            if (dataGridView.CurrentRow == null)
            {
                NotificationTest.NotificationManager nm = new NotificationTest.NotificationManager();
                nm.Show(this, "Veuillez sélectionner un enregistrement pour le modifier", Color.Red, 3000);
            }
            else
            {
                RAMEDEntities1 context = SingletonContext.GetContext();
               
                Dossier_incomplet di = new Dossier_incomplet();
                int id_dossier_incomplet = ((Dossier_incomplet)dataGridView.CurrentRow.DataBoundItem).id_dossier_incomplet;
                di = context.Dossier_incomplet.Where(d => d.id_dossier_incomplet == id_dossier_incomplet).First();
                ModifierDossierForm mdf = new ModifierDossierForm();
                
                mdf.Di = di;
                mdf.Recherchedossierform = this;
                mdf.InitialiserChamps();
                mdf.Show();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }



        private void remplirDataGridView()
        {
            dataGridView.AutoGenerateColumns = false;
            dataGridView.ColumnCount = 6;

            dataGridView.Columns[0].HeaderText = "Num";
            dataGridView.Columns[0].DataPropertyName = "num_dossier";

            dataGridView.Columns[1].HeaderText = "Nom";
            dataGridView.Columns[1].DataPropertyName = "Nom";

            dataGridView.Columns[2].HeaderText = "Prénom";
            dataGridView.Columns[2].DataPropertyName = "Prenom";

            dataGridView.Columns[3].HeaderText = "CIN";
            dataGridView.Columns[3].DataPropertyName = "CIN";

            dataGridView.Columns[4].HeaderText = "champs_manquent";
            dataGridView.Columns[4].DataPropertyName = "champs_manquent";

            dataGridView.Columns[5].HeaderText = "Annexe";
            dataGridView.Columns[5].DataPropertyName = "Annexe_administratif";


            dataGridView.DataSource = DossierRecherches;
        }

        private void Button21_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (dataGridView.CurrentRow == null)
            {
                NotificationTest.NotificationManager nm = new NotificationTest.NotificationManager();
                nm.Show(this, "Veuillez sélectionner un enregistrement pour complet ", Color.Yellow, 3000);
            }
            else
            {
                
                CompletForm CF = new CompletForm();
                CF.recherchedossier = this;
                CF.Di = ((Dossier_incomplet)dataGridView.CurrentRow.DataBoundItem);
                CF.Show();
            }
        }
            
        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {

        }


    }  
}
